<!--
 * @Author: HC
 * @Date: 2022-04-22 14:42:31
 * @LastEditTime: 2022-04-22 17:01:19
 * @Description:
-->
<template>
  <div class="comparison">
    <Dialog content="存增量收入口径：根据资产入网时间定义（新增量：本年1月1日（含）之后; 存增量：上年1月1日（含）到12月31日（含）; 存存量：上年1月1日（不含）前）"></Dialog>
    <div class="table">
      <el-table v-loading="tableLoading" border :header-cell-style="headerClass" :span-method="objectMethod" style="width: 100%" :data="tableData">
        <el-table-column label="分类" prop="type" align="center">
          <el-table-column label="分类" prop="type" align="center"></el-table-column>
          <el-table-column label="分类" prop="cust_type_new" align="center"></el-table-column>
        </el-table-column>
        <el-table-column v-for="(item,index) in headerData" :key="index" :label="item" :prop="'S' + item" align="center"></el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
// import { overallTrend } from "@/api/barCode/index";

import $barCodeApi from "@/api/barCode/index";
import Dialog from './dialog.vue'
export default {
  name: "comparison",
  components: {
    Dialog
  },
  props: {
    form: {
      type: Object,
      default: {},
    },
  },
  data () {
    return {
      tableLoading: false,
      tableData: [],
      headerData: [],
      spanArr1: [],
    };
  },
  computed: {},
  created () { },
  mounted () { },
  methods: {
    getList () {
      this.tableLoading = true;


      $barCodeApi.overallTrend({ ...this.form }, res => {
        if (res.code == 0) {
          this.tableLoading = false;
          this.headerData = res.content.acctMonthS
          this.tableData = res.content.data;
          let contactDot = 0;
          let spanArr1 = [];
          this.tableData.forEach((item, index) => {
            if (index === 0) {
              spanArr1.push(1);
            } else {
              if (item.type === this.tableData[index - 1].type) {
                spanArr1[contactDot] += 1;
                spanArr1.push(0);
              } else {
                contactDot = index;
                spanArr1.push(1);
              }
            }
          });
          this.spanArr1 = spanArr1;
        }
      });









      // overallTrend(this.form).then((res) => {
      //   if (res.code == 0) {
      //     this.tableLoading = false;
      //     this.headerData = res.content.acctMonthS
      //     this.tableData = res.content.data;
      //     let contactDot = 0;
      //     let spanArr1 = [];
      //     this.tableData.forEach((item, index) => {
      //       if (index === 0) {
      //         spanArr1.push(1);
      //       } else {
      //         if (item.type === this.tableData[index - 1].type) {
      //           spanArr1[contactDot] += 1;
      //           spanArr1.push(0);
      //         } else {
      //           contactDot = index;
      //           spanArr1.push(1);
      //         }
      //       }
      //     });
      //     this.spanArr1 = spanArr1;
      //   }
      // });
    },
    objectMethod ({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        if (this.spanArr1[rowIndex]) {
          return {
            rowspan: this.spanArr1[rowIndex],
            colspan: 1,
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0,
          };
        }
      }
    },
    headerClass ({ rowIndex }) {
      if (rowIndex === 1) {
        return { display: 'none' }
      }
      return 'background:#0070C0;color:#FFFF'
    },
  },
};
</script>

<style scoped lang="scss">
</style>
